<template>
	<view>
		<div>
			<navitop>
				<i class="iconfont icon-jiantou-copy" slot="left-slot" @click="outlot"></i>
				<span slot="center-slot">
					<h4>{{titles}}</h4>
				</span>
				<i slot="right-slot">
					<i class="iconfont icon-youcecaidan" style="font-size: 25px;padding-left: 15px;" @click="class_sort"></i>
				</i>
			</navitop>
		</div>
		<div :style="'padding-top:' + nv_height">
			<div class="details">
				<h5 class="detitls_title">基本信息</h5>
				<div class="details_out">
					<div class="details_left">
						采购类型:
					</div>
					<div class="details_right">
						{{dataSorce.purchaseTypeName}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						单据日期:
					</div>
					<div class="details_right">
						{{dataSorce.voucherDate}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						单据编号:
					</div>
					<div class="details_right">
						{{dataSorce.voucherCode}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						部门:
					</div>
					<div class="details_right">
						{{dataSorce.officeName}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						供应商:
					</div>
					<div class="details_right">
						{{dataSorce.vendorName}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						业务员:
					</div>
					<div class="details_right">
						{{dataSorce.salesmanName}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						币种:
					</div>
					<div class="details_right">
						{{dataSorce.currencyName}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						汇率:
					</div>
					<div class="details_right">
						{{dataSorce.exchangeRate}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						付款方式:
					</div>
					<div class="details_right">
						{{dataSorce.payType}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						订金金额:
					</div>
					<div class="details_right">
						{{dataSorce.earnestMoney}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						税率(%):
					</div>
					<div class="details_right">
						{{dataSorce.taxRate}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						总数量:
					</div>
					<div class="details_right">
						{{dataSorce.totalQuantity}}
					</div>
				</div>
			</div>
		</div>
		<div class="details_list details">
			<h5 class="detitls_title">物料列表</h5>
			<div v-for="(item,index) in dataSorce.detailList">
				<div class="details_out">
					<div class="details_left">
						物料编码:
					</div>
					<div class="details_right">
						{{item.inventoryCode}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						物料名称:
					</div>
					<div class="details_right">
						{{item.inventoryName}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						规格型号:
					</div>
					<div class="details_right">
						{{item.inventorySpecification}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						主计量:
					</div>
					<div class="details_right">
						{{item.baseUnitName}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						数量:
					</div>
					<div class="details_right">
						{{item.baseQuantity}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						税率(%):
					</div>
					<div class="details_right">
						{{item.taxRate}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						单价:
					</div>
					<div class="details_right">
						{{item.price}}
					</div>
				</div>
				<div class="details_out">
					<div class="details_left">
						金额:
					</div>
					<div class="details_right">
						{{item.amount}}
					</div>
				</div>
				<div class="details_hr"></div>
			</div>
		</div>
		
		<!-- 气泡弹窗 -->
		<chunLei-popups v-model="value" :popData="datas" @tapPopup="bubble" :x="345" :y="95" placement="top-end">
		</chunLei-popups>
	</view>
</template>

<script>
import navitop from '@/components/common/navi-top'
import chunLeiPopups from "@/components/chunLei-popups/chunLei-popups";
import {DynamicById,Orderexamine,Ordersubmit,Maindelete} from '@/common/api/procure/procureapi.js'
export default {
	components:{
		navitop,
		chunLeiPopups
	},
	data() {
		return {
			titles: '采购订单详情',
			nv_height: '',
			dataSorce: '',
			value: false,
			datas: [{
				title: '提交',
				code: 'purchup',
				icon: 'icon-tijiao'
			},
			{
				title: '撤回提交',
				code: 'purchdow',
				icon: 'icon-tuihui'
			},
			{
				title: '审核',
				code: 'examup',
				icon: 'icon-shenhe'
			},
			{
				title: '弃审',
				code: 'examdow',
				icon: 'icon-icon_function_shenhetuihui'
			},
			{
				title: '修改',
				code: 'purchedit',
				icon: 'icon-xiugai'
			},
			{
				title: '删除',
				code: 'purchdel',
				icon: 'icon-shanchu'
			}],
		
			curl_data:'',
		}
	},
	onLoad(option) {
		this.curl_data = option;
	},
	mounted() {
		this.nv_height = uni.getSystemInfoSync().statusBarHeight + 60 + 'px';
		this.http_data();
	},
	methods: {
		// 获取数据
		http_data(){
			DynamicById({currentId: this.curl_data.id,source: this.curl_data.code,someBusinessType: 0}).then(item => {
				if(item.code == 200){
					this.dataSorce = item.data;
				}
			})
		},
		
		outlot(){
			uni.redirectTo({
				url: '/pages/common/index/procure/common?title=采购订单' + '&code=' + this.curl_data.code + '&sort=0'
			})
		},
		
		// 气泡弹窗
		class_sort(){
			this.value = !this.value;
		},
		
		bubble(val){
			console.log(val)
			// 提交
			if(val.code == 'purchup'){
				this.sbmit_up(this.curl_data.id,0);
			}
			// 撤回提交
			if(val.code == 'purchdow'){
				this.sbmit_up(this.curl_data.id,-1);
			}
			// 审核
			if(val.code == 'examup'){
				this.tmine(this.curl_data.id,1);
			}
			// 弃审
			if(val.code == 'examdow'){
				this.tmine(this.curl_data.id,0);
			}
			// 删除
			if(val.code == 'purchdel'){
				this.purchaseDel();
			}
			
			// 修改
			if(val.code == 'purchedit'){
				uni.navigateTo({
					url: '/pages/common/index/procure/purchaseorder/purchase-edit?title=采购订单' + '&code=' + this.curl_data.code + '&sort=97' + '&id=' + this.curl_data.id
				})
			}
			
		},
		
		//提交/撤回
		sbmit_up(uid,types){
			let alt = '';
			if(types == -1){
				alt = '撤回成功！'
			}
			if(types == 0){
				alt = '提交成功！'
			}
			uni.showLoading({
				title: '加载中...'
			})
			Ordersubmit({id: uid,status: types}).then(item => {
				if(item.code == 200){
					uni.hideLoading();
					uni.showToast({
						title: alt,
						icon: 'none'
					})
				}
			})
		},
		
		//审核/弃审
		tmine(uid,types){
			let alt = '';
			if(types == 1){
				alt = '审核成功！'
			}
			if(types == 0){
				alt = '弃审成功！'
			}
			uni.showLoading({
				title: '加载中...'
			})
			Orderexamine({id: uid,status: types}).then(item => {
				if(item.code == 200){
					uni.hideLoading();
					uni.showToast({
						title: alt,
						icon: 'none'
					})
				}
			})
		},
		
		// 删除
		purchaseDel(){
			let _this = this;
			uni.showLoading({
				title: '加载中...'
			})
			uni.showModal({
				title: '提示',
				content: '确定要删除吗?',
				success(rst) {
					if(rst.confirm){
						Maindelete(_this.curl_data.id).then(item => {
							if(item.code == 200){
								uni.hideLoading();
								uni.showToast({
									title: '删除成功！',
									icon: 'none'
								})
								setTimeout(()=>{
									_this.outlot();
								},1500)
							}
						})
					}else if(rst.cancel){
						console.log('取消')
					}
				}
			})
		},
		
	}
}	
	
</script>

<style scoped lang="scss">
	.details {
		width: 95%;
		margin: auto;
		background-color: #fff;
		box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
		padding: 5px 0 5px 0;
		border-radius: 4px;
		div {
			overflow: hidden;
		}
	}
	.details_out {
		display: flex;
		// height: 25px;
		// line-height: 25px;
		width: 95%;
		margin: auto;
	}
	.details_left {
		width: 30%;
		padding: 0 0 0 10px;
	}
	.details_right {
		width: 60%;
		padding: 0 0 0 5px;
	}
	.detitls_title {
		padding: 5px 0 5px 8px;
		
	}
	.details_list {
		margin-top: 10px;
		border-radius: 4px;
		box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
	}
	.details_hr {
		width: 95%;
		margin: auto;
		border-top: 1px solid #cacaca;
		margin-top: 7px;
	}
</style>
